home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / ace / c / gadget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  6.7 KB  |  368 lines

  1. /* << ACE >>
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** Parser: gadget functions **
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.      Date: 1st,2nd,6th November 1993,
  24.        23rd-25th June 1994,
  25.        10th,12th July 1994,
  26.        12th March 1995,
  27.        6th November 1995
  28. */
  29.  
  30. #include "acedef.h"
  31.  
  32. /* externals */
  33. extern    int    sym;
  34. extern    int    lastsym;
  35.  
  36. /* functions */
  37. void gadget_rectangle()
  38. {
  39. /* (x1,y1)-(x2,y2) */
  40.  
  41.     if (sym != lparen) _error(14);
  42.     else
  43.     {
  44.      insymbol();
  45.      make_sure_long(expr());    /* x1 */
  46.  
  47.      if (sym != comma) _error(16);
  48.      else
  49.      {
  50.       insymbol();
  51.       make_sure_long(expr()); /* y1 */
  52.  
  53.       if (sym != rparen) _error(9);
  54.       else
  55.       {
  56.        insymbol();
  57.        if (sym != minus) _error(21);
  58.        else
  59.        {
  60.         insymbol();
  61.         if (sym != lparen) _error(14);
  62.         else
  63.         {
  64.          insymbol(); 
  65.           make_sure_long(expr());    /* x2 */
  66.  
  67.          if (sym != comma) _error(16);
  68.          else
  69.          {
  70.           insymbol();
  71.            make_sure_long(expr());    /* y2 */
  72.  
  73.           if (sym != rparen) _error(9);
  74.       insymbol();
  75.          }
  76.     }
  77.        }
  78.       }
  79.      }
  80.     }
  81. }
  82.  
  83. void close_gadget()
  84. {
  85. /* GADGET CLOSE gadget-id */
  86.  
  87.     insymbol();
  88.          make_sure_long(expr());    /* gadget-id */
  89.  
  90.     gen("jsr","_CloseGadget","  ");
  91.     gen("addq","#4","sp");
  92.     enter_XREF("_CloseGadget");
  93. }
  94.  
  95. void gadget_output()
  96. {
  97. /*
  98. ** GADGET OUTPUT id
  99. **
  100. ** Make the specified gadget the one from which 
  101. ** information may be obtained via the GADGET(n)
  102. ** function. This allows the value of a string,
  103. ** longint or slider gadget to be obtained at 
  104. ** any time rather than just when a gadget event
  105. ** occurs.
  106. */
  107.     insymbol();
  108.          make_sure_long(expr());    /* gadget-id */
  109.  
  110.     gen("jsr","_SetCurrentGadget","  ");
  111.     gen("addq","#4","sp");
  112.     enter_XREF("_SetCurrentGadget");
  113. }
  114.  
  115. void wait_gadget()
  116. {
  117. /* GADGET WAIT gadget-id */
  118.  
  119.     insymbol();
  120.          make_sure_long(expr());    /* gadget-id */
  121.     
  122.     gen("jsr","_WaitGadget","  ");
  123.     gen("addq","#4","sp");
  124.     enter_XREF("_WaitGadget");
  125. }
  126.  
  127. void modify_gadget()
  128. {
  129. /* 
  130. ** GADGET MOD gadget-id,knob-position[,max-position] 
  131. **
  132. ** For the modification of (proportional) gadgets.
  133. */
  134.  
  135.     insymbol();
  136.         make_sure_long(expr());    /* gadget-id */
  137.     
  138.     if (sym != comma) _error(16);
  139.     else
  140.     {
  141.         insymbol();
  142.             make_sure_long(expr());    /* knob-position */
  143.  
  144.         /* specify new maximum notches for slider? */
  145.         if (sym != comma) 
  146.             gen("move.l","#-1","-(sp)");
  147.         else
  148.         {
  149.             insymbol();
  150.                 make_sure_long(expr());    /* max-position */
  151.         }
  152.  
  153.         /* call function */
  154.         gen("jsr","_modify_gad","  ");
  155.         gen("add.l","#12","sp");
  156.         
  157.         enter_XREF("_modify_gad");
  158.         enter_XREF("_GfxBase");
  159.     }
  160. }
  161.  
  162. void gadget()
  163. {
  164. /* GADGET gadget-id,status[,gadget-value,(x1,y1)-(x2,y2),type[,style][,font,size,txtstyle]]
  165.    GADGET MOD gadget-id,knob-pos[,max-notches]
  166.    GADGET WAIT gadget-id
  167.    GADGET CLOSE gadget-id
  168.    GADGET ON | OFF | STOP
  169. */
  170. int  gtype;
  171.  
  172.     insymbol();
  173.     
  174.     if (sym == onsym || sym == offsym || sym == stopsym)
  175.         change_event_trapping_status(lastsym);
  176.     else
  177.     if (sym == closesym)
  178.         close_gadget();
  179.     else
  180.     if (sym == outputsym)
  181.         gadget_output();
  182.     else
  183.         if (sym == waitsym)
  184.         wait_gadget();
  185.     else
  186.     if (sym == modsym)
  187.         modify_gadget();
  188.     else
  189.     {
  190.             make_sure_long(expr());    /* gadget-id */
  191.  
  192.          if (sym != comma) _error(16);
  193.          else
  194.          {
  195.              insymbol();
  196.             if (sym == onsym)
  197.             {
  198.                 gen("move.l","#1","-(sp)");
  199.                 insymbol();
  200.             }
  201.             else
  202.             if (sym == offsym)
  203.             {
  204.                 gen("move.l","#0","-(sp)");
  205.                 insymbol();
  206.             }
  207.             else
  208.             {
  209.                 /* status */
  210.                 make_sure_long(expr());
  211.             }
  212.  
  213.             if (sym != comma)
  214.             {
  215.                 gen("jsr","_ChangeGadgetStatus","  ");
  216.                 gen("addq","#8","sp");
  217.  
  218.                 enter_XREF("_ChangeGadgetStatus");
  219.                 enter_XREF("_GfxBase");    
  220.                 return;    
  221.             }
  222.          }
  223.  
  224.         if (sym != comma) _error(16);
  225.         else
  226.         {
  227.             insymbol();
  228.             gtype = expr();    
  229.  
  230.             /* string or integer expression for 3rd parameter */
  231.             if (gtype != stringtype)
  232.             {
  233.                 make_sure_long(gtype);
  234.             }
  235.         }
  236.  
  237.         if (sym != comma) _error(16);
  238.         else
  239.         {
  240.             insymbol();
  241.             gadget_rectangle();    /* (x1,y1)-(x2,y2) */
  242.  
  243.             if (sym != comma) _error(16);
  244.             else
  245.             {
  246.                 /* 
  247.                 ** Gadget Type.
  248.                 */
  249.                  insymbol();
  250.  
  251.                 if (sym == buttonsym)
  252.                 {
  253.                     gen("move.l","#1","-(sp)");
  254.                     insymbol();
  255.                 }
  256.                 else
  257.                 if (sym == stringsym)
  258.                 {
  259.                     gen("move.l","#2","-(sp)");
  260.                     insymbol();
  261.                 }
  262.                 else
  263.                 if (sym == longintsym)
  264.                 {
  265.                     gen("move.l","#3","-(sp)");
  266.                     insymbol();
  267.                 }
  268.                 else
  269.                 if (sym == potxsym)
  270.                 {
  271.                     gen("move.l","#4","-(sp)");
  272.                     insymbol();
  273.                 }
  274.                 else
  275.                 if (sym == potysym)
  276.                 {
  277.                     gen("move.l","#5","-(sp)");
  278.                     insymbol();
  279.                 }
  280.                 else
  281.                 {
  282.                     /* type */
  283.                     make_sure_long(expr());
  284.                 }
  285.             }
  286.  
  287.             /*
  288.             ** Optional gadget style parameter.
  289.             */
  290.             if (sym != comma)
  291.                 gen("move.l","#0","-(sp)");    /* style = 0 */
  292.             else
  293.             {
  294.                  insymbol();
  295.  
  296.                 if (sym != comma)
  297.                     make_sure_long(expr());    /* style */
  298.                 else
  299.                     gen("move.l","#0","-(sp)");  /* style = 0 */    
  300.             }            
  301.         
  302.             /*
  303.             ** Optional font and font-size parameters (for button).
  304.             */
  305.             if (sym != comma)
  306.             {
  307.                 gen("move.l","#0","-(sp)");  /* font name = NULL */
  308.                 gen("move.l","#0","-(sp)");  /* font size = 0 */
  309.                 gen("move.l","#0","-(sp)");  /* font style = 0 */
  310.             }
  311.             else
  312.             {
  313.                 insymbol();
  314.                 if (expr() != stringtype)    /* font name */
  315.                     _error(4);
  316.                 else
  317.                 {
  318.                     if (sym != comma) 
  319.                         _error(16);
  320.                     else
  321.                     {
  322.                          insymbol();
  323.                         make_sure_long(expr());    /* font size */
  324.                     }
  325.  
  326.                     if (sym != comma) 
  327.                         _error(16);
  328.                     else
  329.                     {
  330.                          insymbol();
  331.                         make_sure_long(expr());    /* font style */
  332.                     }
  333.                 }
  334.             }                    
  335.      }
  336.  
  337.      /* call function */
  338.      gen("jsr","_CreateGadget","  ");
  339.      gen("add.l","#48","sp");
  340.  
  341.      enter_XREF("_CreateGadget");
  342.      enter_XREF("_GfxBase");
  343.     }
  344. }
  345.  
  346. void    bevel_box()
  347. {
  348. /* 
  349. ** BEVELBOX (x1,y1)-(x2,y2),type
  350. */
  351.     insymbol();
  352.  
  353.     gadget_rectangle();
  354.     if (sym != comma) _error(16);
  355.     else
  356.     {
  357.         insymbol();
  358.         make_sure_long(expr());    /* type */
  359.  
  360.          /* call function */
  361.         gen("jsr","_BevelBox","  ");
  362.         gen("add.l","#20","sp");
  363.  
  364.         enter_XREF("_BevelBox");
  365.         enter_XREF("_GfxBase");
  366.     }
  367. }
  368.